package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 3.1查询所有护理等级
     */
    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult<NursingLevelVo> selectAllNursingLevel() {
        List<NursingLevelVo> vo = nursingLevelService.selectAllNursingLevel();
        return success(vo);
    }

    /**
     * 3.3条件分页查询
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<NursingLevelVo> paramQuery(
            @ApiParam(value = "护理计划名称") String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingLevelVo> vo = nursingLevelService.selectQuery(status, name, pageNum, pageSize);
        return success(vo);
    }

    /**
     * 3.2护理等级新增
     */
    @ApiOperation("护理等级新增")
    @PostMapping("/insert")
    public ResponseResult insertNursingLevel(@RequestBody NursingLevelDto dto) {
        nursingLevelService.insertNursingLevel(dto);
        return success();
    }

    /**
     * 3.4根据id查询
     */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> selectNursingLevelById(@PathVariable Long id) {
        NursingLevelVo vo = nursingLevelService.selectNursingLevelById(id);
        return success(vo);
    }

    /**
     * 3.5 修改护理等级
     */
    @ApiOperation("修改护理等级")
    @PutMapping("/update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto dto) {
        nursingLevelService.updateNursingLevel(dto);
        return success();
    }

    /**
     * 3.6 删除护理计划
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteNursingLevelById(@PathVariable Long id) {
        nursingLevelService.deleteNursingLevelById(id);
        return success();
    }

    /**
     *  护理计划的禁用启用
     */
    @ApiOperation("护理计划的禁用启用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理等级id") @PathVariable Long id,
            @ApiParam(value = "状态：0-禁用，1-启用") @PathVariable Integer status
    ){
        nursingLevelService.updateStatus(id,status);
        return success();
    }
}
